package com.nio;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

public class Transfer {
    public static void main(String[] args) throws IOException {
        RandomAccessFile accessFile1 = new RandomAccessFile("F:\\test.txt", "rw");
        FileChannel fromChannel = accessFile1.getChannel();

        RandomAccessFile accessFile2 = new RandomAccessFile("F:\\2.txt", "rw");
        FileChannel toChannel = accessFile2.getChannel();

        // 把fromChannel的数据传输到toChannel中
        // transferFrom
        long position = 0;
        long size = fromChannel.size();
//        long transfer = toChannel.transferFrom(fromChannel, position, size);
//        System.out.println(transfer);

        long transfer2 = toChannel.transferTo(position, size,fromChannel);
        System.out.println(transfer2);

    }
}
